package com.s.core.root.strategy.factor.pics.combination;

import com.google.common.collect.Lists;
import com.s.core.root.data._AllData;
import com.s.core.root.strategy.base.Factor;
import com.s.core.root.strategy.base.Feature;
import com.s.core.root.strategy.factor.pic.F_Pic_ActivityPair;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Pics特征：描述含非Max波动的Pic的个数
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class F_Pics_ActivityPair implements Factor, Feature {
    private List<Integer> ns;

    /**
     * 含非Max波动的Pic的个数
     */
    public long size(Integer limitN) {
        return ns.stream().filter(n -> {
            if (limitN == null) {
                return true;
            } else {
                return n <= limitN;
            }
        }).count();
    }

    @Override
    public void process(_AllData allData) {
        List<Integer> picNs = Lists.newArrayList();
        allData.picNMap.values().stream().
                filter(picN -> picN.containFeature(F_Pic_ActivityPair.class)).
                forEach(picN -> picNs.add(picN.getN()));
        if (!picNs.isEmpty()) {
            allData.addFeature(new F_Pics_ActivityPair(picNs));
        }
    }
}